Ensure metadata for libs/bins are distinct
authorAlex Crichton <alex@alexcrichton.com>
Fri, 26 Feb 2016 22:27:53 +0000 (14:27 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 26 Feb 2016 22:27:53 +0000 (14:27 -0800)
It may be the case in the future that the compiler will require that the "salt"
(the `-C metadata` flag) for all crates with the same name are distinct. Right
now a Cargo project with a library and a binary, however, will have the same
salt with the same crate name.

This commit mixes in some extra data to the library's salt to ensure that its
symbols don't clash with the binary's.

src/cargo/util/toml.rs

index 7ff7251b2e6964804fdf2e2f3b1ed15fdc2de5c2..00b66e267e673c92521119668939fadcab012b7a 100644 (file)
@@ -835,9 +835,14 @@ fn normalize(lib: &Option<TomlLibTarget>,
             }
         };
 
+        // Binaries, examples, etc, may link to this library. Their crate names
+        // have a high likelihood to being the same as ours, however, so we need
+        // some extra metadata in our name to ensure symbols won't collide.
+        let mut metadata = metadata.clone();
+        metadata.mix(&"lib");
         let mut target = Target::lib_target(&l.name(), crate_types,
                                             &path.to_path(),
-                                            metadata.clone());
+                                            metadata);
         configure(l, &mut target);
         dst.push(target);
     }